package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.nursing.vo.TimeCountVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Tag(name =  "预约信息相关接口")
public class MemberReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;

    @GetMapping("/cancelled-count")
    @Operation(description = "查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();
        reservationService.getCancelledCount(userId);


        System.out.println("------"+userId);
        return R.ok(1);
    }

    @GetMapping("/countByTime")
    @Operation(description = "查询每个时间段剩余预约次数")
    public R<List<TimeCountVo>> list(){
        Long userId = UserThreadLocal.getUserId();
        List<TimeCountVo> timeCountVoList = reservationService.countReservationsForTime(userId);
        return R.ok(timeCountVoList);
    }

    @PostMapping("")
    @Operation(description = " 新增预约")
    public R<Void> add(@RequestBody ReservationDto reservationDto){
        reservationService.insertReservation(reservationDto);
        return R.ok();
    }
    @GetMapping("/page")
    @Operation(description = "分页查询预约")
    public R<TableDataInfo<Reservation>> page(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) Integer status) {
        TableDataInfo<Reservation> tableDataInfo = reservationService.selectByPage(pageNum, pageSize, status);
        return R.ok(tableDataInfo);
    }

    @PutMapping("/{id}/cancel")
    public R<Void> delete(@PathVariable Long id){
        reservationService.cancelReservation(id);
        return R.ok();
    }
}